unit U_hhost;

interface
uses HStruct,u_units,sysutils,Pmanager;
var
  BaseDirectory,PlayDirectory,ScenName:string;
  capfile,armyfile,racefile,unitfile,cityfile,mapfile:string;
  ScenPath:string;

Procedure ExplodeUnits(dir:string;pla:Tpa);
Procedure MakeOneFirstRST(dir:string;race:byte);
Procedure UnpackOneFirstRST(dest,rn:string);
implementation

Procedure UnpackOneFirstRst;
var
 na:rname;
 us:string;
 p:integer;
begin
 p:=pos('.',rn);
 if p<>0 then
  if (rn[p+1]='f') and (rn[p+2]='s') and (rn[p+3]='t') then
  begin
   us:=rn[p-1];
   if us='0' then us:='10';
   na[1]:='comm'+us+'.dat';na[2]:='udata'+us+'.dat'; na[3]:='citcom'+us+'.dat';
   na[4]:='map.map'; na[5]:='tnum'+us+'.dat';na[6]:='cdata'+us+'.dat';na[7]:='pdata.dat';na[8]:='money'+us+'.dat';
   na[9]:='armies.dat';na[10]:='race.nm';na[11]:='captain.nm';na[12]:='techl'+us+'.dat';na[13]:='dipl'+us+'.dat';
   ExplodePack(13,dest,rn,na);
  end;
end;

Procedure MakeOneFirstRST;
var
 na:rname;
 us:string;
begin
 us:=inttostr(race);
 na[1]:='comms'+us+'.dat';na[2]:='units'+us+'.dat'; na[3]:='citcom'+us+'.dat';
 na[4]:='mdata.hht'; na[5]:='tnum'+us+'.dat';na[6]:='cdata.hht';na[7]:='pdata.dat';na[8]:='money'+us+'.dat';
 na[9]:='armies.dat';na[10]:='race.nm';na[11]:='captain.nm';na[12]:='techl'+us+'.dat';na[13]:='dipl'+us+'.dat';
 MakePack(13,dir,'player'+us+'.fst',na);
end;

Procedure ExplodeUnits(dir:string;pla:Tpa);
var
 j,i:integer;
 f:file of Runit;
 r:Runit;
 us:string;
begin
 huts.LoadFromFile(dir+'udata.hht');
 for i:=1 to 10 do if pla.exist(i) then begin
  us:=inttostr(i);
  assignfile(f,dir+'units'+us+'.dat');rewrite(f);
  for j:=0 to huts.count do begin
   if huts.units[j].Race=i then write(f,huts.units[j]);
  end;
  closefile(f);
 end;
end;

end.
